/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pb138.videodes.impl;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import cz.muni.fi.pb138.videodes.api.base.RowMapper;
import cz.muni.fi.pb138.videodes.entity.Dvd;
import cz.muni.fi.pb138.videodes.entity.DvdConverter;
import cz.muni.fi.pb138.videodes.entity.Movie;
import org.xmldb.api.base.Resource;
import org.xmldb.api.base.XMLDBException;

/**
 *
 * @author pseudo
 */
public class DvdRowMapper implements RowMapper<Dvd> {

    @Override
    public Dvd map(Resource rs) throws XMLDBException {
	XStream x = new XStream(new DomDriver());
	x.registerConverter(new DvdConverter());
	x.alias("dvd", Dvd.class);
	x.alias("movie", Movie.class);
	
	Dvd dvd = (Dvd) x.fromXML(rs.getContent().toString());
	
	return dvd;
    }
    
}
